#include <memory>
#include <iostream>

using std::cout;
using std::endl;
using std::auto_ptr;

class Point
{
public:
    Point(int ix, int iy)
    : _ix(ix)
    , _iy(iy)
    {   cout << "Point(int,int)" << endl;   }

    ~Point()
    {   cout << "~Point()" << endl; }

    void print() const
    {   
        cout << "(" << _ix
             << "," << _iy
             << ")" << endl;
    }

private:
    int _ix;
    int _iy;
};

void test0()
{
    Point * pt = new Point(1, 2);
    auto_ptr<Point> ap(pt);
    ap->print();
    (*ap).print();
    cout << endl;

    //拷贝构造函数
    //从语法形式上看起来是一个拷贝操作，
    //但底层已经发生了所有权的转移
    auto_ptr<Point> ap2 = ap;
    ap2->print();
    (*ap2).print();
    cout << endl;

    //此时的ap中托管的指针已经被置为空了,从而导致发生段错误
    //auto_ptr存在缺陷，C++17中直接被丢弃了
    ap->print();
    (*ap).print();
    cout << "1111 " << endl;
}


int main()
{
    test0();

    return 0;
}

